package org.example;

import java.time.Duration;
import java.time.LocalDateTime;

public class test {
    public static void main(String[] args) {
        LocalDateTime startTime = LocalDateTime.of(2022, 11, 6, 2, 0, 0);
        LocalDateTime endTime = LocalDateTime.of(2022, 11, 6, 2, 30, 0);

        LocalDateTime springTime = LocalDateTime.of(2022, 3, 13, 3, 0, 0);
        LocalDateTime fallTime = LocalDateTime.of(2022, 11, 6, 2, 59, 59);

        Duration duration = null;
        if (startTime.isBefore(endTime)) {
            duration = Duration.between(startTime, endTime);
        } else {
            duration = Duration.between(endTime, startTime);
        }
        long days = duration.toDays();
        System.out.println("day:"+days);
        long hours = duration.toHours();
        System.out.println("hour:"+hours);
        long minutes = duration.toMinutes();
        System.out.println("minutes"+minutes);
        long seconds = duration.toSeconds();
        System.out.println("seconds"+seconds);

        long timelength = 0;
        if (seconds%60 > 0) timelength = minutes + 1;
        else timelength = minutes;
        System.out.println("minutes:"+timelength);

        double cost0;
        if(timelength <= 20 && timelength >= 1) {cost0 = timelength*0.05;}
        else if(timelength < 1) {cost0 = 0.05;}
        else {cost0 = (long) (1 + 0.1*(timelength-20));}
        System.out.println("cost0:"+cost0);

        double cost;
        boolean flag = false;
        if (springTime.isAfter(startTime) && springTime.isBefore(endTime)) {
            cost = cost0-6;
            flag = true;
            System.out.println(cost);
        } else if (fallTime.isAfter(startTime) && fallTime.isBefore(endTime)) {
            cost = cost0+6;
        } else {
            cost = cost0;
        }
        System.out.println(flag);
        System.out.println(cost);
    }
}
